package com.jeesite.modules.billnorecord.service;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.jeesite.common.callback.MethodCallback;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.idgen.IdGen;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeesite.common.entity.Page;
import com.jeesite.common.service.CrudService;
import com.jeesite.modules.billnorecord.entity.BillNoRecord;
import com.jeesite.modules.billnorecord.dao.BillNoRecordDao;

/**
 * 单据编码记录表Service
 *
 * @author 码脑洞
 * @version 2025-04-13
 */
@Service
public class BillNoRecordService extends CrudService<BillNoRecordDao, BillNoRecord> {

	/**
	 * 获取单条数据
	 *
	 * @param billNoRecord
	 * @return
	 */
	@Override
	public BillNoRecord get(BillNoRecord billNoRecord) {
		return super.get(billNoRecord);
	}

	/**
	 * 查询分页数据
	 *
	 * @param billNoRecord 查询条件
	 * @param billNoRecord page 分页对象
	 * @return
	 */
	@Override
	public Page<BillNoRecord> findPage(BillNoRecord billNoRecord) {
		return super.findPage(billNoRecord);
	}

	/**
	 * 查询列表数据
	 *
	 * @param billNoRecord
	 * @return
	 */
	@Override
	public List<BillNoRecord> findList(BillNoRecord billNoRecord) {
		return super.findList(billNoRecord);
	}

	/**
	 * 保存数据（插入或更新）
	 *
	 * @param billNoRecord
	 */
	@Override
	@Transactional
	public void save(BillNoRecord billNoRecord) {
		super.save(billNoRecord);
	}

	/**
	 * 更新状态
	 *
	 * @param billNoRecord
	 */
	@Override
	@Transactional
	public void updateStatus(BillNoRecord billNoRecord) {
		super.updateStatus(billNoRecord);
	}

	/**
	 * 删除数据
	 *
	 * @param billNoRecord
	 */
	@Override
	@Transactional
	public void delete(BillNoRecord billNoRecord) {
		super.delete(billNoRecord);
	}

	public BillNoRecord init(Long billNoPatternId, Integer seq, String cSerial, String code) {
		BillNoRecord billNoRecord = new BillNoRecord();
		billNoRecord.setAutoId(IdGen.autoId());
		billNoRecord.setPatternId(billNoPatternId);
		billNoRecord.setSeq(seq);
		billNoRecord.setSerial(cSerial);
		billNoRecord.setCode(code);
		return billNoRecord;
	}

	public void saveBillNoRecord(Long billNoPatternId, Integer seq, String cSerial, String code) {
		BillNoRecord billnoRecord = init(billNoPatternId, seq, cSerial, code);
		dao.insert(billnoRecord);
	}

	public void insertBatch(List<BillNoRecord> billNoRecords) {
		if (ObjectUtil.isNotEmpty(billNoRecords)) {
			ListUtils.pageList(billNoRecords, 50, new MethodCallback() {
				@Override
				@SuppressWarnings("unchecked")
				public Object execute(Object... objs) {
					return dao.insertBatch((List<BillNoRecord>) objs[0]);
				}
			});
		}
	}

}